<?
 $title = "Status pages";
 $dir = "../";
 include($dir."inc/header.inc.php");
 include("exclude.inc.php");
 require("sks.inc.php");
 require("sks-status.inc.php");
 
 $servers = unserialize(file_get_contents(dirname(__FILE__)."/sks_cache.serialized"));
 $status_collection = unserialize(file_get_contents(dirname(__FILE__)."/sks_cache_status_collection.serialized"));
 $servercolarr = $status_collection->get_servers();
 #echo "<p style=\"border: 1px solid black; background-color: orange;\">We're sorry for instabilities as of late, but there were some hardware issues. These should now be fixed.</p>"; 
 #echo "<p style=\"border: 1px solid black; background-color: yellow;\">IPv6 connectivity is down due to <a style=\"font-weight: bold;\" href=\"https://www.sixxs.net/pops/phonera/\">issues with the tunnel provider</a>.</p>";
 echo "<p>These statistics were last updated: ".date("Y-m-d H:i",$servers->get_time())." (CET)</p>";
 echo "<h1>Servers in the pool</h1>";
 echo "<p>Information about the various pools is <a href=\"/overview-of-pools.php\">found here</a><br /></p>"; 
 echo "<table class=\"list\">\n";
 echo "<tr><th>&nbsp;</th><th>Hostname</th><th>HKP Status</th><th>IPv6?</th><th>Version</th><th>Keys</th><th>SRV weight</th><th>Stats</th><th>Meta</th></tr>\n";
 $serverarr = $servers->get_servers();
 sort($serverarr);
 $nonrespserver = array();
 
 $c1 = "#fff"; 
 $c2 = "#b4cad8"; 
 $c = 0;
 $counter = 1;
 
 foreach($serverarr as $server)
 {
  if($servercolarr[$server->get_hostname()]['last_status']!=1)
  {
   $nonrespserver[] = array($server->get_hostname(),$server->get_port(),$server->get_statusok(),$server->get_version(),$server->get_numkeys());
  }
  else
  {
   if(in_array($server->get_hostname(),$exclude)) continue;
   $cu = (($c==1) ? $c2 : $c1);

   echo "<tr>";
   echo "<td style=\"background-color: {$cu};\">{$counter}</td>";
   echo "<td style=\"background-color: {$cu};\"><a href=\"http://{$server->get_hostname()}:{$server->get_port()}\">{$server->get_hostname()}</a></td>";
   echo "<td style=\"background-color: green; margin:none; padding:none;\"></td>";
   echo "<td style=\"background-color: ".(($server->get_ipv6() === true) ? "green" : "red")."; margin:none; padding:none;\"></td>";
   echo "<td style=\"background-color: {$cu};\">{$server->get_version()}</td>";
   echo "<td style=\"background-color: {$cu};\">{$server->get_numkeys()}</td>";
   echo "<td style=\"background-color: {$cu};\">{$server->get_srvweight()}</td>";
   echo "<td style=\"background-color: {$cu};\"><a href=\"http://{$server->get_hostname()}:{$server->get_port()}/pks/lookup?op=stats\">Stats</a></td>";
   echo "<td style=\"background-color: {$cu};\"><a href=\"info/{$server->get_hostname()}\">Meta</a></td>";
   echo "</tr>\n";
   $c = (($c==1) ? 0 : 1);
   $counter++;
  }
 }
 echo "</table>\n";
 
 echo "<h1>Servers currently not in the pool</h1>";
 echo "<p>These servers were detected when iterating though keyserver synchronisation peers, but did not respond in a timely manner to the HKP request or lack more than 500 keys compared to keys.kfwebs.net.</p>";
 echo "<table class=\"list\">\n";
 echo "<tr><th>&nbsp;</th><th>Hostname</th><th>HKP Status</th><th>Version</th><th>Keys</th><th>Stats</th><th>Meta</th></tr>\n";

 $c = 0;
 $counter = 1;

 foreach($nonrespserver as $server)
 {
  if(in_array($server[0],$exclude)) continue;
  $cu = (($c==1) ? $c2 : $c1);
  echo "<tr><td style=\"background-color: {$cu};\">{$counter}</td><td style=\"background-color: {$cu};\">".(($server[2]==1) ? "<a href=\"http://{$server[0]}:{$server[1]}/\">{$server[0]}</a>" : $server[0])."</td><td style=\"background-color: ".(($server[2]==1) ? "green" : "red").";\"></td><td style=\"background-color: {$cu};\">{$server[3]}</td><td style=\"background-color: {$cu};\">{$server[4]}</td><td style=\"background-color: {$cu};\"><a href=\"http://{$server[0]}:{$server[1]}/pks/lookup?op=stats\">Stats</a></td>";
  echo "<td style=\"background-color: {$cu};\"><a href=\"info/{$server[0]}\">Meta</a></td>";
  echo "</tr>\n";
  $c = (($c==1) ? 0 : 1);
  $counter++;
 }
 echo "</table>";
 include($dir."inc/footer.inc.php");
?>
